package com.flong.common;

import java.io.UnsupportedEncodingException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * @Description Base64Util   
 * @ClassName   Base64Util  
 * @Date        2017�?6�?7�? 下午5:39:05  
 * @Author      liangjilong  
 * @Copyright (c) All Rights Reserved, 2017.
 */
public class Base64Util {
	
	/**
     * @Description 加密  
     * @Author      liangjilong  
     * @Date        2017�?6�?7�? 下午5:40:42  
     * @param text
     * @return 参数  
     * @return String 返回类型   
     * @throws
	 */
    public static String Base64Encoder(String text) {  
        byte[] b = null;  
        String s = null;  
        try {  
            b = text.getBytes("utf-8");  
        } catch (UnsupportedEncodingException e) {  
            e.printStackTrace();  
        }  
        if (b != null) {  
            s = new BASE64Encoder().encode(b);  
        }  
        return s;  
    }  
  
    /**
     * @Description 解密    
     * @Author      liangjilong  
     * @Date        2017�?6�?7�? 下午5:40:51  
     * @param text
     * @return 参数  
     * @return String 返回类型   
     * @throws
     */
    public static String Base64Decoder(String text) {  
        byte[] b = null;  
        String result = null;  
        if (text != null) {  
            BASE64Decoder decoder = new BASE64Decoder();  
            try {  
                b = decoder.decodeBuffer(text);  
                result = new String(b, "utf-8");  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
        }  
        return result;  
    }  

    public static void main(String[] args) {
    	System.out.println(Base64Encoder("123"));
    	System.out.println(Base64Decoder(Base64Encoder("123")));
	}
    
    
}
